<!--
 * @Descripttion: 网站入口-生态伙伴合作-信息收集
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2025-06-10
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2025-06-12
-->
<script lang="ts" setup>
  import { Form, message } from 'ant-design-vue'
  import { reactive, ref } from 'vue'

  import { requestPartnerCooperationSave } from '/@/api/business/dataMarket/partnerCooperation'
  import { HttpCodeEnum } from '/@/enums/httpEnum'
  import { PartnerJoinImgEnum } from '/@/enums/imageEnum'

  /** 提交状态-枚举 */
  enum SubmitStatusEnum {
    /** 未提交 */
    NOT_SUBMIT = 'NOT_SUBMIT',
    /** 提交中 */
    SUBMITTING = 'SUBMITTING',
    /** 提交成功 */
    SUBMIT_SUCCESS = 'SUBMIT_SUCCESS',
  }

  /** 提交状态 */
  const submitStatus = ref(SubmitStatusEnum.NOT_SUBMIT)

  /** 表单字段 */
  const formState = reactive({
    /** 公司名称 */
    companyName: '',
    /** 您的姓名 */
    contactName: '',
    /** 您的电话 */
    contactPhone: '',
    /** 业务需求（选填） */
    businessDemand: '',
  })

  /** 表单校验规则 */
  const formRule = reactive({
    /** 公司名称 */
    companyName: [{ required: true, message: '请输入公司名称' }],
    /** 您的姓名 */
    contactName: [{ required: true, message: '请输入您的姓名' }],
    /** 您的电话 */
    contactPhone: [{ required: true, message: '请输入您的电话' }],
  })

  /** 表单hook */
  const { validate, validateInfos, resetFields } = Form.useForm(formState, formRule)

  /**
   * 保存
   */
  const save = async () => {
    submitStatus.value = SubmitStatusEnum.SUBMITTING
    validate()
      .then(async () => {
        const { responseCode } = await requestPartnerCooperationSave(formState)
        if (responseCode === HttpCodeEnum.SUCCESS) {
          submitStatus.value = SubmitStatusEnum.SUBMIT_SUCCESS
          message.success('添加成功')
        } else {
          submitStatus.value = SubmitStatusEnum.NOT_SUBMIT
        }
      })
      .catch(() => {
        submitStatus.value = SubmitStatusEnum.NOT_SUBMIT
      })
  }

  /**
   * 再次填写
   */
  const writeAgain = () => {
    resetFields()
    submitStatus.value = SubmitStatusEnum.NOT_SUBMIT
  }
</script>

<template>
  <div class="partner-join">
    <img class="bg" :src="PartnerJoinImgEnum.bg" />
    <div class="title">生态合作伙伴</div>
    <div class="info">
      <div class="info-step">
        <div class="info-step-item">
          <img class="img" :src="PartnerJoinImgEnum.step01" />
          <span class="name">提交信息</span>
          <span class="desc">请填写提交真实的信息</span>
        </div>
        <div class="info-step-item">
          <img class="img" :src="PartnerJoinImgEnum.step02" />
          <span class="name">后台审核</span>
          <span class="desc">工作人员会在1～3个工作日进行查看审核</span>
        </div>
        <div class="info-step-item">
          <img class="img" :src="PartnerJoinImgEnum.step03" />
          <span class="name">电话沟通</span>
          <span class="desc">审核通过后会与您进一步沟通合作诉求</span>
        </div>
        <div class="info-step-item">
          <img class="img" :src="PartnerJoinImgEnum.step04" />
          <span class="name">权限发放</span>
          <span class="desc">确认诉求后向您发放系统体验账号</span>
        </div>
        <div class="info-step-line left"></div>
        <div class="info-step-line center"></div>
        <div class="info-step-line right"></div>
      </div>
      <div class="info-success" v-if="submitStatus === SubmitStatusEnum.SUBMIT_SUCCESS">
        <img class="info-success-logo" :src="PartnerJoinImgEnum.success" />
        <div class="info-success-title">提交成功</div>
        <div class="info-success-desc">工作人员会在3个工作日与您进行电话沟通，请耐心等待</div>
        <button class="info-success-again" @click="writeAgain()">再次填写</button>
      </div>
      <div class="info-form" v-else>
        <div class="info-form-title">请填写信息，云海链专员将与您联系</div>
        <div class="info-form-content">
          <a-form layout="vertical">
            <a-form-item label="公司名称" v-bind="validateInfos.companyName">
              <a-input v-model:value="formState.companyName" :bordered="false" placeholder="请输入" />
            </a-form-item>
            <a-form-item label="您的姓名" v-bind="validateInfos.contactName">
              <a-input v-model:value="formState.contactName" :bordered="false" placeholder="请输入" />
            </a-form-item>
            <a-form-item label="您的电话" v-bind="validateInfos.contactPhone">
              <a-input v-model:value="formState.contactPhone" type="number" :bordered="false" placeholder="请输入" />
            </a-form-item>
            <a-form-item label="业务需求（选填）" v-bind="validateInfos.businessDemand">
              <a-textarea v-model:value="formState.businessDemand" show-count :maxlength="300" :bordered="false" placeholder="可详细填写您的业务诉求，如医药研发，营销推广等，以便工作人员更高效的和您沟通" />
            </a-form-item>
            <a-form-item>
              <a-button class="btn-submit" type="primary" :loading="submitStatus === SubmitStatusEnum.SUBMITTING" @click="save()">提交</a-button>
            </a-form-item>
          </a-form>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .partner-join {
    position: relative;
    margin-top: -60px;

    .bg {
      width: 100%;
    }

    .title {
      position: absolute;
      top: 140px;
      left: 0;
      right: 0;
      margin: auto;
      height: 48px;
      text-align: center;
      line-height: 48px;
      font-size: 48px;
      font-weight: 600;
      color: #1d2129;
    }

    .info {
      position: absolute;
      top: 238px;
      left: 0;
      right: 0;
      width: 1200px;
      height: 750px;
      margin: auto;
      border-radius: 16px;
      background: rgb(255 255 255 / 90%);

      .info-step {
        position: relative;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 120px;
        border: 2px dashed #fff;
        border-radius: 16px 16px 0 0;
        background: #e8f3ff;

        .info-step-line {
          position: absolute;
          top: 64px;
          width: 13%;
          height: 1px;
          background: #c9cdd4;

          &.left {
            left: 18.5%;
          }

          &.center {
            left: 0;
            right: 0;
            margin: auto;
          }

          &.right {
            right: 18.5%;
          }
        }

        .info-step-item {
          flex: 1;
          display: flex;
          flex-direction: column;
          align-items: center;

          .img {
            width: 43px;
            height: 47px;
          }

          .name {
            margin-top: -9px;
            height: 28px;
            line-height: 28px;
            font-size: 20px;
            font-weight: 600;
            color: #000;
          }

          .desc {
            margin-top: 4px;
            height: 22px;
            line-height: 22px;
            font-size: 14px;
            color: #4e5969;
          }
        }
      }

      .info-success {
        padding-top: 110px;

        .info-success-logo {
          display: block;
          width: 80px;
          height: 80px;
          margin: auto;
        }

        .info-success-title {
          height: 32px;
          margin-top: 24px;
          text-align: center;
          line-height: 32px;
          font-size: 24px;
          font-weight: 500;
          color: #000;
        }

        .info-success-desc {
          height: 24px;
          margin-top: 8px;
          text-align: center;
          line-height: 24px;
          font-size: 16px;
          color: #000;
        }

        .info-success-again {
          display: block;
          width: 480px;
          height: 54px;
          margin: 40px auto 0;
          border: none;
          border-radius: 30px;
          font-size: 18px;
          background: #f2f3f5;
          color: #1d2129;
          cursor: pointer;
        }
      }

      .info-form {
        width: 640px;
        padding-top: 40px;
        margin: auto;

        .info-form-title {
          height: 32px;
          line-height: 32px;
          font-size: 24px;
          font-weight: 500;
          color: #000;
        }

        .info-form-content {
          margin-top: 32px;

          :deep(.ant-form-item-control) {
            input.ant-input {
              height: 36px;
              border-radius: 2px;
              background: #f2f3f5;
            }

            textarea.ant-input {
              height: 100px;
              border-radius: 2px;
              background: #f2f3f5;
            }
          }

          .btn-submit {
            width: 100%;
            height: 54px;
            margin-top: 12px;
            text-align: center;
            border: none;
            border-radius: 30px;
            font-size: 18px;
            font-weight: 500;
            background: linear-gradient(270deg, #39bffc 0%, #246af3 94.05%);
            color: #fff;
          }
        }
      }
    }
  }
</style>
